# coding:utf8

import pymysql.cursors


def insert_to_mysql():
    conn = pymysql.connect(host='localhost',
                           user='root',
                           password='root',
                           db='omdb2',
                           charset='utf8mb4',
                           cursorclass=pymysql.cursors.DictCursor)

    arr = [x.strip() for x in open('./emoji.txt', 'rt', encoding='utf8')]

    try:
        with conn.cursor() as cursor:
            sql = "INSERT INTO `t_names` (`name`) VALUES (%s)"
            for x in arr:
                cursor.execute(sql, (x,))

        conn.commit()
    finally:
        conn.close()


if __name__ == '__main__':
    insert_to_mysql()



